<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="utf-8">
        <title>
           	 二级类型管理
        </title>
        <meta name="renderer" content="webkit"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
        <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
        <meta name="apple-mobile-web-app-capable" content="yes"/>
        <meta name="format-detection" content="telephone=no"/>
        <link rel="stylesheet" href="/houtaistatic/css/x-admin.css" media="all"/>
    </head>
    <script src="/houtaistatic/js/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#add").click(function () {
                if(confirm("确认添加嘛")){
                    var typeNamevar = document.getElementById("typeName");
                    if(typeNamevar.validity.valueMissing==true){
                        typeNamevar.setCustomValidity("名称不能为空");
                        return;
                    }else{
                        typeNamevar.setCustomValidity("");
                    }
                    $.ajax({
                        url: "/traveltype/add?typeName="+typeNamevar.value+"&parentLeven="+$("#fu").val(),
                        type: "POST",
                        dataType: "text",
                        error:function(){
                            alert("添加失败");

                        },
                        success: function(data) {
                            if(data=="0"){
                                alert("添加失败")
                            } else if(data=="-2"){
                                alert("类型已存在");
                            }else{
                                alert("添加成功！");
                                typeNamevar.value="";
                                $("#x-link").append("<tr><td><input type='checkbox' value='1' name=''></td><td >"+data.id+"</td><td >"+data.typeName+"</td><td >"+data.createTime+"</td><td class='td-manage'><a title='删除' href='#' onclick='commemt_del(this,)' class='delete' dataid='"+data.id+"' style='text-decoration:none'><i class='layui-icon'>&#xe640;</i></a></td></tr>")
                            }
                        }
                    });
                }
            });
            $(".delete").click(function () {
                var deleteid = $(this).attr("dataid");
                var index  =$(".delete").index(this);
               // alert(index);
                if(confirm("确定是否删除？？？？")){
                    $.ajax({
                        url: "/traveltype/deleteSonByid?id="+deleteid,
                        type: "POST",
                        dataType: "text",
                        error:function(){
                            alert("删除失败");

                        },
                        success: function(data) {
                            if(data=="0"){
                                alert("删除失败")
                            } else if(data=="-2"){
                                alert("请先删除其他引用此类型得二级类型");
                            }else{
                                alert("删除成功");
                                $('table tr').eq(index).remove();
                            }
                        }
                    });
                }
            });
        });
    </script>
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>类型管理</cite></a>
              <a><cite>二级类型管理</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </div>
        <div class="x-body">
            <form>
	            <select name="selectfu" id="fu">
	                <option th:each="hun:${baList}" th:text="${hun.typeName}" th:value="${hun.id}"></option>
	            </select>
                <input name="typeName" type="text" placeholder="请输入类型名称" id="typeName" required/>
                <input name="add" id ="add" type="button" value="添加"/>
            </form>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>
                            <input type="checkbox" name="" value="">
                        </th>
                        <th>
                            编号
                        </th>
                        <th>
                            名称
                        </th>
                        <th>
                            父级名称
                        </th>
                        <th>
                            创建时间
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody id="x-link">
                    <tr  th:each="emp : ${sonList}">
                        <td>
                            <input type="checkbox" value="1" name="">
                        </td>
                        <td th:text="${emp.id}">
                            1
                        </td>
                        <td th:text="${emp.typeName}">
                            erdangjiade
                        </td>
                        <td th:text="${emp.fuName}">
                            商品建议
                        </td>
                        <td th:text="${emp.createTime}" >
                            826096331@qq.com
                        </td>
                        <td class="td-manage">
                            <a title="删除" href="#" onclick="commemt_del(this,)" class="delete"  th:dataid="${emp.id}"
                               style="text-decoration:none">
                                <i class="layui-icon">&#xe640;</i>
                            </a>
                        </td>
                    </tr>
                </tbody>
            </table>

            <div id="page"></div>
        </div>
        <script src="../houtaistaitc/lib/layui/layui.js" charset="utf-8"></script>
        <script src="../houtaistaitc/js/x-layui.js" charset="utf-8"></script>
        <script>
            layui.use(['element','laypage','layer','form'], function(){
                $ = layui.jquery;//jquery
              lement = layui.element();//面包导航
              laypage = layui.laypage;//分页
              layer = layui.layer;//弹出层
              form = layui.form();//弹出层


          })

            //批量删除提交
             function delAll () {
                layer.confirm('确认要删除吗？',function(index){
                    //捉到所有被选中的，发异步进行删除
                    layer.msg('删除成功', {icon: 1});
                });
             }
            
            

            // 编辑
            function feedback_edit (title,url,id,w,h) {
                x_admin_show(title,url,w,h); 
            }
            
            /*删除*/
            function feedback_del(obj,id){
                layer.confirm('确认要删除吗？',function(index){
                    //发异步删除数据
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                });
            }
            </script>
            <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
        </script>

    </body>
</html>